<title>淘单业绩</title>
<!--当前位置开始-->
<div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
        <script type="text/html" template lay-done="layui.data.updateMainBreadcrumb();">
        </script>
    </div>
</div>
<!--当前位置结束-->
<style>
    /* 重写样式 */
</style>
<script type="text/html" template lay-type="Post" lay-url="{{ layui.setter.apiUrl }}Api/CoreCmsUser/GetIndex" lay-done="layui.data.done(d);">
</script>
<div class="table-body">
    <table id="LAY-app-CoreCmsUser3-tableBox" lay-filter="LAY-app-CoreCmsUser3-tableBox"></table>
</div>

<script type="text/html" id="LAY-app-CoreCmsUser3-toolbar">
    <form class="layui-form coreshop-toolbar-search-form" id="LAY-app-CoreCmsUser3-toolbar-form">
        <div class="layui-form-item">
            <div class="layui-row">
                <div class="layui-col-md12">
                    <div class="layui-inline layui-input-wrap layui-input-wrap-prefix">
                        <div class="layui-input-inline">
                            <div class="layui-input-prefix">
                                <i class="layui-icon"></i>
                            </div>
                            <select name="companyId" lay-filter="select-companyId-filter">
                                <option value="">请选择公司</option>
                                {{# layui.each(indexData.companyList, function(index, item){ }}
                                <option value="{{ item.id }}">{{ item.companyName }}</option>
                                {{# }); }}
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline layui-input-wrap layui-input-wrap-prefix">
                        <div class="layui-input-inline">
                            <div class="layui-input-prefix">
                                <i class="layui-icon"></i>
                            </div>
                            <select id="departmentSelect" name="departmentId" lay-filter="select-departmentId-filter">
                                <option value="">请选择部门</option>
                                <!--{{# layui.each(indexData.departmentList, function(index, item){ }}
                <option value="{{ item.id }}">{{ item.depName }}</option>
                {{# }); }}-->
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline layui-input-wrap layui-input-wrap-prefix">
                        <div class="layui-input-inline">
                            <div class="layui-input-prefix">
                                <i class="layui-icon"></i>
                            </div>
                            <select name="groupId" id="groupIdSelect" lay-filter="select-groupId-filter">
                                <option value="">请选择组别</option>
                {{# layui.each(indexData.groupList, function(index, item){ }}
                <option value="{{ item.id }}">{{item.groupName }}</option>
                {{# }); }}
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">时间范围：</label>
                        <div class="layui-input-inline layui-inline-6">
                            <input type="text" name="date" value="" id="date" placeholder="请输入起止时间" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn layui-btn-sm" lay-submit lay-filter="LAY-app-CoreCmsUser3-search" id="LAY-app-CoreCmsUser3-search"><i class="layui-icon layui-icon-search"></i>筛选</button>
                        <!--<button class="layui-btn layui-btn-primary layui-btn-sm" lay-submit lay-filter="LAY-app-CoreCmsUser-clearSearch"><i class="layui-icon layui-icon-delete"></i>取消</button>-->
                    </div>
                    <!--<div class="layui-inline layui-input-wrap layui-input-wrap-prefix">
        <div class="layui-input-inline">
            <div class="layui-input-prefix">
                <i class="layui-icon"></i>
            </div>
            <select name="sourceId">
                <option value="">请选择来源</option>
                {{# layui.each(indexData.sourceList, function(index, item){ }}
                <option value="{{ item.id }}">{{ item.userName }}</option>
                {{# }); }}
            </select>
        </div>
    </div>-->
                    <!--<div class="layui-inline layui-input-wrap layui-input-wrap-prefix">
        <div class="layui-input-inline">
            <div class="layui-input-prefix">
                <i class="layui-icon layui-icon-test"></i>
            </div>
            <select name="customerClassId">
                <option value="">请选择客户分类</option>
                {{# layui.each(indexData.customerClassList, function(index, item){ }}
                <option value="{{ item.id }}">{{ item.className }}</option>
                {{# }); }}
            </select>
        </div>
    </div>-->
                    <!--<div class="layui-inline layui-input-wrap layui-input-wrap-prefix">
        <div class="layui-input-inline">
            <div class="layui-input-prefix">
                <i class="layui-icon layui-icon-slider"></i>
            </div>
            <select name="customerGroupId">
                <option value="">客户群组</option>
                {{# layui.each(indexData.customerGroupList, function(index, item){ }}
                <option value="{{ item.id }}">{{item.groupName }}</option>
                {{# }); }}
            </select>
        </div>
    </div>-->
                    <!--<div class="layui-inline layui-input-wrap layui-input-wrap-prefix">
        <div class="layui-input-inline">
            <div class="layui-input-prefix">
                <i class="layui-icon layui-icon-dollar"></i>
            </div>
            <select name="paymentCode">
                <option value="">请选择支付方式</option>
                {{# layui.each(indexData.paymentCode, function(index, item){ }}
                <option value="{{ item.title }}">{{ item.description }}</option>
                {{# }); }}
            </select>
        </div>
    </div>-->
                </div>
            </div>

            <div class="layui-row">
                <div class="layui-col-md12">
                    <!--<div class="layui-inline layui-input-wrap layui-input-wrap-prefix">
                        <div class="layui-input-inline">
                            <div class="layui-input-prefix">
                                <i class="layui-icon layui-icon-list"></i>
                            </div>
                            <input type="text" name="number" placeholder="客户编号" class="layui-input">
                        </div>
                    </div>-->
                    <!--<div class="layui-inline layui-input-wrap layui-input-wrap-prefix">
                        <div class="layui-input-inline">
                            <div class="layui-input-prefix">
                                <i class="layui-icon"></i>
                            </div>
                            <input type="text" name="userName" placeholder="请输入名字" class="layui-input">
                        </div>
                    </div>-->
                    <!--<div class="layui-inline layui-input-wrap layui-input-wrap-prefix">
                        <div class="layui-input-inline">
                            <div class="layui-input-prefix">
                                <i class="layui-icon layui-icon-cols"></i>
                            </div>
                            <input type="text" name="mobile" placeholder="请输入客户电话" class="layui-input">
                        </div>
                    </div>-->
                    <!--<div class="layui-inline layui-input-wrap layui-input-wrap-prefix">
                        <div class="layui-input-inline">
                            <div class="layui-input-prefix">
                                <i class="layui-icon"></i>
                            </div>
                            <select name="status">
                                <option value="">请选择时间模式</option>
                                {{# layui.each(indexData.timeList, function(index, item){ }}
                                <option value="{{ item.value }}">{{ item.description }}</option>
                                {{# }); }}
                            </select>
                        </div>
                    </div>-->
                    <!--<div class="layui-inline layui-input-wrap layui-input-wrap-prefix">
                        <div class="layui-input-inline core-time-input ">
                            <div class="layui-input-prefix">
                                <i class="layui-icon layui-icon-time"></i>
                            </div>
                            <input type="text" name="createTime" id="searchTime-CoreCmsUser-createTime" placeholder="请选择时间" class="layui-input">
                        </div>
                    </div>-->
                 
                </div>
            </div>


        </div>
    </form>
</script>

<script type="text/html" id="LAY-app-CoreCmsUser3-pagebar">
    <div class="layui-btn-container" style="display:none">
        <button class="layui-btn layui-btn-sm" lay-event="addData"><i class="layui-icon layui-icon-add-1"></i>添加数据</button>
        <button class="layui-btn layui-btn-sm" lay-event="inputData"><i class="layui-icon layui-icon-add-1"></i>导入数据</button>
        <button class="layui-btn layui-btn-sm" lay-event="selectExportExcel"><i class="layui-icon layui-icon-add-circle"></i>选择导出</button>
        <button class="layui-btn layui-btn-sm" lay-event="queryExportExcel"><i class="layui-icon layui-icon-download-circle"></i>查询导出</button>
    </div>
</script>

<script type="text/html" id="LAY-app-CoreCmsUser3-tableBox-bar">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <!--<a class="layui-btn layui-btn-xs" lay-event="editBalance">修改余额</a>
    <a class="layui-btn layui-btn-xs" lay-event="editPoint">修改积分</a>
    <a class="layui-btn layui-btn-xs" lay-event="editParentId">修改推荐人</a>-->
    <a class="layui-btn layui-btn-xs" lay-event="addFollowRecords">跟进</a>
    <a class="layui-btn layui-btn-xs" lay-event="addOrder">下单</a>
</script>

<script>
    var indexData;
    layui.data.done = function (d) {
        indexData = d.data;
        console.log(d.data);
        layui.use(['index', 'table', 'laydate', 'util', 'coreHelper'],
            function () {
                var $ = layui.$
                    , admin = layui.admin
                    , table = layui.table
                    , form = layui.form
                    , laydate = layui.laydate
                    , setter = layui.setter
                    , coreHelper = layui.coreHelper
                    , util = layui.util
                    , view = layui.view;


                var searchwhere;
                //监听搜索
                form.on('checkbox', function (data) {
                    console.log(data, 'data--->')

                    if (data.elem.className === 'custom-radio') {
                        console.log("当前选中：", data.value);

                        // 先清空所有选中项
                        document.querySelectorAll(".custom-radio").forEach(checkbox => {
                            checkbox.checked = false;
                        });

                        // 只保留当前点击的项
                        data.elem.checked = true;

                        // 重新渲染表单，使 UI 正确显示
                        setTimeout(() => {
                            form.render('checkbox');
                        }, 50);
                        return false
                    }

                });
                form.on('select(select-companyId-filter)', function (data) {
                    var elem = data.elem; // 获得 select 原始 DOM 对象
                    var value = data.value; // 获得被选中的值
                    var othis = data.othis; // 获得 select 元素被替换后的 jQuery 对象

                    layer.msg(this.innerHTML + ' 的 value: ' + value); // this 为当前选中 <option> 元素对象

                    coreHelper.Post("Api/SysUser/DepartmentList", { id: value }, function (e) {
                        console.log(e, "hhhhh");

                        $('#departmentSelect').empty();
                        $('#groupIdSelect').empty();

                        if (e.data.length > 0) {
                            var firstValue = 0;
                            $.each(e.data, function (h, z) {
                                $('#departmentSelect').append("<option value=" + z.id + ">" + z.depName + "</option>")
                                if (h == 0) {
                                    firstValue = z.id;
                                }
                                console.log("dfsfsdfsd", z.id);
                            });

                            if (firstValue) {
                                coreHelper.Post("Api/SysUser/GroupList", { id: firstValue }, function (ed) {
                                    console.log(ed);

                                    if (ed.data.length > 0) {
                                        $('#groupIdSelect').empty();
                                        // $('#groupIdSelect').value();
                                        $.each(ed.data, function (hd, zd) {
                                            $('#groupIdSelect').append("<option value=" + zd.id + ">" + zd.groupName + "</option>")
                                        });
                                        document.getElementById('groupIdSelect').value = '';
                                        form.render();
                                    }
                                });

                            }
                     
                            document.getElementById('departmentSelect').value = '';
                            console.log(firstValue);
                        }
                        form.render();

                    });
                });

                form.on('select(select-departmentId-filter)', function (data) {

                    console.log(data, 'data--->')
                    var elem = data.elem; // 获得 select 原始 DOM 对象
                    var value = data.value; // 获得被选中的值
                    var othis = data.othis; // 获得 select 元素被替换后的 jQuery 对象
                    layer.msg(this.innerHTML + ' 的 value: ' + value); // this 为当前选中 <option> 元素对象

                    coreHelper.Post("Api/SysUser/GroupList", { id: value }, function (e) {
                        console.log(e);
                        $('#groupIdSelect').empty();

                        if (e.data.length > 0) {
                            // $('#groupIdSelect').value();
                            $.each(e.data, function (h, z) {
                                $('#groupIdSelect').append("<option value=" + z.id + ">" + z.groupName + "</option>")
                            });
                        }
                        document.getElementById('groupIdSelect').value = '';
                        form.render();
                    });

                });


          
 
             
                //监听搜索
                form.on('submit(LAY-app-CoreCmsUser3-search)',
                    function (data) {
                        var field = data.field;
                        console.log("cecccc", field);
                        searchwhere = field;
                        //执行重载
                        table.reloadData('LAY-app-CoreCmsUser3-tableBox', { where: field, page: false } });
                        return false; // 阻止默认 form 跳转
                    });

                //监听清空
                form.on('submit(LAY-app-CoreCmsUser-clearSearch)',
                    function (data) {
                        $('#LAY-app-CoreCmsUser-toolbar-form')[0].reset();
                        //执行重载
                        table.reloadData('LAY-app-CoreCmsUser-tableBox', { where: "", page: false });
                        return false; // 阻止默认 form 跳转
                    });
                //数据绑定
                table.render({
                    elem: '#LAY-app-CoreCmsUser3-tableBox',
                    url: "Api/CoreCmsReports/GetReportOrderTD",
                    method: 'POST',
                    toolbar: '#LAY-app-CoreCmsUser3-toolbar',
                    className: 'pagebarbox',
                    defaultToolbar: ['filter', 'print', 'exports'],
                    height: 'full-132',//无面包屑127,搜索框189,1行62
                    totalRow: true,  // 全局开启合计行
                    text: { none: '暂无相关数据' },
                    cols: [
                        [
                            { field: 'companyName', title: '公司名称', align: 'center', width: 80, totalRow: true },
                            { field: 'depName', title: '部门', align: 'center', width: 80, totalRow: true },
                            { field: 'groupName', title: '组别', align: 'center', width: 80, totalRow: true },
                            { field: 'nickName', title: '姓名', align: 'center', width: 80, totalRow: true },
                            { field: 'val', title: '下单金额', align: 'center', width: 80, totalRow: true },
                            { field: 'num', title: '下单数量', align: 'center', width: 80, totalRow: true },
                            { field: 'sendAmount', title: '发货金额', align: 'center', width: 80, totalRow: true },
                            { field: 'sendCount', title: '发货数量', align: 'center', width: 80, totalRow: true },
                            { field: 'signedAmount', title: '签收金额', align: 'center', width: 80, totalRow: true },
                            { field: 'signedCount', title: '签收数量', align: 'center', width: 80, totalRow: true },
                            { field: 'completeAmount', title: '完成金额', align: 'center', width: 80, totalRow: true },
                            { field: 'completeCount', title: '完成数量', align: 'center', width: 80, totalRow: true },
                            { field: 'refundAmount', title: '退货金额', align: 'center', width: 80, totalRow: true },
                            { field: 'refundCount', title: '退货数量', align: 'center', width: 80, totalRow: true },
         
                         
                        ]
                    ]
                });
                //监听排序事件
                table.on('sort(LAY-app-CoreCmsUser3-tableBox)', function (obj) {
                    table.reloadData('LAY-app-CoreCmsUser3-tableBox', {
                        initSort: obj, //记录初始排序，如果不设的话，将无法标记表头的排序状态。
                        where: { //请求参数（注意：这里面的参数可任意定义，并非下面固定的格式）
                            orderField: obj.field, //排序字段
                            orderDirection: obj.type //排序方式
                        }
                    });
                });

        

       

               

                //监听 表格复选框操作

            

                laydate.render({
                    elem: '#searchTime-CoreCmsUser-createTime',
                    range: '到',
                    type: 'datetime'
                });
                laydate.render({
                    elem: '#searchTime-updataTime',
                    range: '到',
                    type: 'datetime'
                });
                //重载form
                form.render();
                //时间插件
                var date = new Date();
                layui.laydate.render({
                    elem: '#date',
                    range: '到',
                    type: 'date',
                    value: util.toDateString(date, 'yyyy-MM-dd') + ' 到 ' + util.toDateString(date, 'yyyy-MM-dd'),
                    trigger: 'click'
                });


            });
    };
</script>

<!--设置删除标志 有数据就是删除-->
<script type="text/html" id="switch_isDelete">
    <input type="checkbox" name="switch_isDelete" value="{{d.id}}" lay-skin="switch" lay-text="已删除|正常" lay-filter="switch_isDelete" {{ d.isDelete ? 'checked' : '' }}>
</script>